package com.example.howard.xiao7music.ui.adapter.RemoteAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.howard.xiao7music.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Howard on 2016/10/26.
 */
public class RankingListAdapter extends BaseAdapter {

    private List<Map<String,Object>> rankinglist=new ArrayList<>();
    private LayoutInflater inflater;

    public RankingListAdapter (Context c){

        this.inflater = LayoutInflater.from(c);

        Map<String ,Object> map=new HashMap<>();
        map.put("title",R.drawable.ranking1);
        map.put("name","新歌榜");
        rankinglist.add(map);
        map=new HashMap<>();
        map.put("title",R.drawable.ranking2);
        map.put("name","热歌榜");
        rankinglist.add(map);
        map=new HashMap<>();
        map.put("title",R.drawable.ranking21);
        map.put("name","欧美金曲榜");
        rankinglist.add(map);
        map=new HashMap<>();
        map.put("title",R.drawable.ranking22);
        map.put("name","经典老歌榜");
        rankinglist.add(map);
         map=new HashMap<>();
        map.put("title",R.drawable.ranking23);
        map.put("name","情歌对唱榜");
        rankinglist.add(map);
        map=new HashMap<>();
        map.put("title",R.drawable.ranking25);
        map.put("name","网络歌曲榜");
        rankinglist.add(map);
    }

    @Override
    public int getCount() {
        return rankinglist.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView,
                        ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.ranking_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.title = (ImageView) convertView
                    .findViewById(R.id.ranking_logo);
            viewHolder.ranking_name = (TextView) convertView
                    .findViewById(R.id.ranking_name);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.title.setImageDrawable(convertView.getResources().getDrawable(rankinglist.get(position).get("title").hashCode()));

        viewHolder.ranking_name.setText(rankinglist.get(position).get("name").toString());



        return convertView;
    }

    class ViewHolder {
        ImageView title;
        TextView ranking_name;

    }
}
